package com.example.app.ui.components

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.pager.VerticalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.app.viewmodel.MainViewModel

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun NotificationContent(vm: MainViewModel) {
    val pagerState = rememberPagerState(pageCount = { vm.notifications.size })
    Row(
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.SpaceBetween,
        modifier = Modifier
            .padding(8.dp)
            .clip(RoundedCornerShape(8.dp))
            .background(Color(0x22149EE7))
            .fillMaxWidth()
            .padding(horizontal=8.dp)
            .height(45.dp)
    ) {
        Text(text = "最新活动", color = Color(0xFF149EE7), fontSize = 14.sp)
        Spacer(modifier = Modifier.width(8.dp))
        VerticalPager(
            state = pagerState,
            modifier = Modifier.weight(1f)
        ) { index ->
            Text(
                text = vm.notifications[index],
                color = Color(0xFF333333),
                fontSize = 14.sp,
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
                lineHeight = 45.sp,
                modifier = Modifier.fillMaxWidth()
            )
        }
        Spacer(modifier = Modifier.width(8.dp))
        Text(text = "更多", color = Color(0xFF666666), fontSize = 14.sp, maxLines = 1)
    }
}

@Preview(showBackground = true)
@Composable
fun NotificationContentPreview(vm: MainViewModel = viewModel()) {
    NotificationContent(vm)
}

